package com.mini.controller;

import com.alibaba.fastjson.JSONObject;
import com.mini.common.config.CheckLogin;
import com.mini.es.service.EsMiniStatisticDataNewService;
import com.mini.util.DateUtil;
import com.mini.vo.BusinessResult;
import com.mini.vo.MiniStatisticDataAllVO;
import com.mini.vo.MiniStatisticPageParamNew;
import com.mini.vo.PageResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 项目名称：mini-data-es
 * 类 名 称：ThrowDataKanbanController
 * 类 描 述：TODO
 * 创建时间：2021/4/8 下午6:00
 * 创 建 人：zhanghuiying
 */
@Slf4j
@RestController
@RequestMapping(value = "/kanban")
@Api(tags = {"看板数据统计API"}, description = "看板数据统计")
public class ThrowDataKanbanController extends BaseController {

    @Autowired
    private EsMiniStatisticDataNewService mnsStatisticKanbanService;

    @CheckLogin
    @PostMapping(value = "/pageLevel")
    @ApiOperation(value = "广告投放数据看板接口")
    public BusinessResult<PageResultVO<MiniStatisticDataAllVO>> getPageLevel1(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                                                              @RequestBody MiniStatisticPageParamNew param) throws Exception {
        try {
            //参数验证
            if (param == null) {
                throw new IllegalArgumentException("参数为空！");
            }
            //默认一个周期，前一天14点到当天14点
            if (param.getPageNumber() == null || param.getPageNumber() <= 0) {
                param.setPageNumber(1);
            }

            //默认当天
            if (StringUtils.isBlank(param.getDateEnd())) {
                param.setDateEnd(DateUtil.getTodayString());
            }
            if (StringUtils.isBlank(param.getDateStart())) {
                param.setDateStart(param.getDateEnd());
            }
            PageResultVO<MiniStatisticDataAllVO> page = mnsStatisticKanbanService.pageListLevel1(param);

//            log.info("shuju=========={}", JSONObject.toJSON(page));
            log.info("查询结束=======");
            return BusinessResult.createSuccessInstance(page);

        } catch (Exception e) {
            log.error("查询数据异常",e);
            return BusinessResult.createInstance(1111L,"查询数据异常",null);
        }
    }
}
